package rollercoaster.railway;

import java.util.ArrayList;
import java.util.List;


import rollercoaster.commons.Vertex3D;
import rollercoaster.commons.interfaces.ICurve3D;

public class RoundedRectangle implements ICurve3D{
	
	private float a;
	private float b;
	private float rounded_portion;
	private UniformSecondOrderClosedBSpline usocbs;
	

	public RoundedRectangle(float a, float b, float rounded_portion) {
		super();
		if(rounded_portion<=0 || rounded_portion>Math.min(a, b)/4) rounded_portion=Math.min(a, b)/8;
		this.a = a;
		this.b=b;
		this.rounded_portion = rounded_portion;
		usocbs=new UniformSecondOrderClosedBSpline(new ArrayList<Vertex3D>());
		configureSpline();
	}
	
	private void configureSpline(){
		List<Vertex3D> list=new ArrayList<Vertex3D>();
		list.add(new Vertex3D(a/2, b/2-2*rounded_portion, 0));
		list.add(new Vertex3D(a/2, b/2,0));
		list.add(new Vertex3D(a/2-2*rounded_portion, b/2, 0));
		list.add(new Vertex3D(-(a/2-2*rounded_portion), b/2, 0));
		list.add(new Vertex3D(-a/2, b/2, 0));
		list.add(new Vertex3D(-a/2, b/2-2*rounded_portion, 0));
		list.add(new Vertex3D(-a/2, -(b/2-2*rounded_portion), 0));
		list.add(new Vertex3D(-a/2, -b/2, 0));
		list.add(new Vertex3D(-(a/2-2*rounded_portion), -b/2, 0));
		list.add(new Vertex3D(a/2-2*rounded_portion, -b/2, 0));
		list.add(new Vertex3D(a/2, -b/2, 0));
		list.add(new Vertex3D(a/2, -(b/2-2*rounded_portion), 0));
		usocbs.setControlPoints(list);
	}
	

	public Vertex3D gamma(float t) {
		return usocbs.gamma(t);
	}

	public Vertex3D dGammadt(float t) {
		return usocbs.dGammadt(t);
	}

	public float getStartPoint() {
		return usocbs.getStartPoint();
	}

	public float getEndPoint() {
		return usocbs.getEndPoint();
	}

	

	public float getA() {
		return a;
	}

	public float getB() {
		return b;
	}

	public float getRounded_portion() {
		return rounded_portion;
	}

	
	
}
